package com.itheima.ai.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.ai.entity.po.SpringAiChatRecord;
import com.itheima.ai.mapper.SpringAiChatRecordMapper;
import com.itheima.ai.service.ISpringAiChatRecordService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class SpringAiChatRecordServiceImpl extends ServiceImpl<SpringAiChatRecordMapper, SpringAiChatRecord> implements ISpringAiChatRecordService {

    @Override
    public void saveRecord(String type, String conversionId) {
        Long count = this.lambdaQuery()
                .eq(SpringAiChatRecord::getId, conversionId)
                .eq(SpringAiChatRecord::getType, type)
                .count();
        if (count != null && count > 0) {
            // 记录已存在，结束
            return;
        }
        SpringAiChatRecord record = new SpringAiChatRecord();
        record.setType(type);
        record.setId(conversionId);
        record.setUserId(1L);
        record.setCreateTime(LocalDateTime.now());
        save(record);
    }

    @Override
    public List<String> findConversationIds(String type) {
        return this.getBaseMapper().findConversationIds(type, 1L);
    }
}
